// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';

import 'package:lmmi/view/home/page.dart';

void main() {
  group('HomePage Widget Tests', () {
    testWidgets('HomePage should display top section with username', (
      WidgetTester tester,
    ) async {
      // Build our app and trigger a frame.
      await tester.pumpWidget(
        ProviderScope(
          child: ScreenUtilInit(
            designSize: const Size(375, 812),
            child: MaterialApp(home: HomePage()),
          ),
        ),
      );

      // Verify that the HomePage is displayed
      expect(find.byType(HomePage), findsOneWidget);

      // Verify that the username is displayed (should show 'Guest' when no user is logged in)
      expect(find.text('Guest'), findsOneWidget);
    });

    testWidgets('HomePage should display date scroll list', (
      WidgetTester tester,
    ) async {
      await tester.pumpWidget(
        ProviderScope(
          child: ScreenUtilInit(
            designSize: const Size(375, 812),
            child: MaterialApp(home: HomePage()),
          ),
        ),
      );

      // Verify that the ListView for dates is present
      expect(find.byType(ListView), findsOneWidget);

      // Verify that some weekday names are displayed
      expect(find.text('Mon'), findsOneWidget);
      expect(find.text('Tue'), findsOneWidget);
      expect(find.text('Wed'), findsOneWidget);
    });

    testWidgets('HomePage should display calendar button with today\'s date', (
      WidgetTester tester,
    ) async {
      await tester.pumpWidget(
        ProviderScope(
          child: ScreenUtilInit(
            designSize: const Size(375, 812),
            child: MaterialApp(home: HomePage()),
          ),
        ),
      );

      // Verify that the calendar button displays today's date
      final now = DateTime.now();
      final dayNames = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
      final monthNames = [
        'Jan',
        'Feb',
        'Mar',
        'Apr',
        'May',
        'Jun',
        'Jul',
        'Aug',
        'Sep',
        'Oct',
        'Nov',
        'Dec',
      ];

      final dayName = dayNames[now.weekday - 1];
      final monthName = monthNames[now.month - 1];
      final expectedDateString = '$dayName, ${now.day} $monthName';

      expect(find.text(expectedDateString), findsOneWidget);
    });
  });
}
